package com.ficus.road.maintain.handler.smartdecision.strategy;

import com.ficus.road.maintain.core.model.HitTypeEnum;
import com.ficus.road.maintain.core.model.smartnew.SmartDecisionExcelVO;
import com.ficus.road.maintain.core.model.smartnew.SmartDecisionResponse;
import com.ficus.road.maintain.core.model.smartnew.SmartInitialScreening;
import com.ficus.road.maintain.core.model.smartnew.SmartRoadDisease;
import com.ficus.road.maintain.dao.SmartRoadDiseaseDao;
import com.ficus.road.maintain.handler.smartdecision.enums.SmartDecisionStrategyEnum;
import com.google.common.base.Joiner;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author xiawen yang
 * @date 2022/7/21 下午1:55
 */
@Component
@RequiredArgsConstructor
public class SmartDecisionHighwayDiscoveryStrategy implements ISmartDecisionStrategy {

    private final SmartRoadDiseaseDao smartRoadDiseaseDao;

    @Override
    public SmartDecisionStrategyEnum getStrategy() {
        return SmartDecisionStrategyEnum.HIGHWAY_DISCOVERY;
    }

    @Override
    public SmartDecisionResponse process(List<SmartDecisionExcelVO> params, SmartDecisionResponse response) {
        // todo: 智能发现逻辑待补充
        List<SmartRoadDisease> smartRoadDiseases = smartRoadDiseaseDao.findAll();
        Map<String, List<SmartRoadDisease>> roadVerticalMap = smartRoadDiseases.stream().collect(Collectors.groupingBy(hit -> {
            Joiner joiner = Joiner.on("_");
            return joiner.join(Arrays.asList(hit.getRoadName(), hit.getStartStake(), hit.getEndStake()));
        }));
        roadVerticalMap.forEach((road, hitList) -> {
            SmartInitialScreening smartInitialScreening = new SmartInitialScreening();
            hitList.forEach(hit -> {

            });
        });
        response.getSmartDiscoveryResponse().setSmartDetectCount(smartRoadDiseases.size());
        return response;
    }

    @Getter
    public enum InitialScreeningEnum {
        /**
         *
         */
        ASPHALT_CRAZING("ROAD_TYPE_ASPHALT", HitTypeEnum.PIC_CRACK_RESULT_CRACKED, 1),
        ASPHALT_CRACKED("ROAD_TYPE_ASPHALT", HitTypeEnum.PIC_CRACK_RESULT_PIC_CRACK, 0.5),
        ASPHALT_SETTLEMENT("ROAD_TYPE_ASPHALT", HitTypeEnum.PIC_POTHOLES_RESULT_SETTLEMENT, 1.5),
        ASPHALT_DEPRESSION("ROAD_TYPE_ASPHALT", HitTypeEnum.PIC_POTHOLES_RESULT_DEPRESSION, 1.5),
        CEMENT_CRACKED("ROAD_TYPE_CEMENT", HitTypeEnum.PIC_CRACK_RESULT_PIC_CRACK, 0.5),
        CEMENT_BROKEN_BOARD("ROAD_TYPE_CEMENT", HitTypeEnum.PIC_CRACK_RESULT_BROKEN_BOARD, 1);

        private final String roadType;

        private final HitTypeEnum hitType;

        private final double weight;


        InitialScreeningEnum(String roadType, HitTypeEnum hitType, double weight) {
            this.roadType = roadType;
            this.hitType = hitType;
            this.weight = weight;
        }

//        @Override
//        public String toString() {
//            return "InitialScreeningEnum{" +
//                    "roadType='" + roadType + '\'' +
//                    ", hitType=" + hitType +
//                    '}';
//        }


    }
}
